package net.pessu.android.shoppoid.debrief;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.database.Cursor;

import net.pessu.android.shoppoid.bean.Article;
import net.pessu.android.shoppoid.dao.Database;
import net.pessu.android.shoppoid.gui.IhmObjets;
import net.pessu.android.shoppoid.util.StringUtils;

public class DebriefService {

	private static DebriefService instance;

	private Database db;

	public DebriefService(Debrief debriefContext) {
		this.db = Database.getInstance(debriefContext);
	}

	public DebriefService() {
	}

	public static DebriefService getInstance(Debrief debriefContext) {
		if (null == instance) {
			instance = new DebriefService(debriefContext);
		}
		return instance;
	}

	public static DebriefService getInstance() {
		if (null == instance) {
			instance = new DebriefService();
		}
		return instance;
	}

	public List<Article> getListArticlesAchetes() {
		return db.retrieveArticlesAchetes();
	}
	
	public Cursor getListArticlesAchetesC() {
		return db.retrieveArticlesAchetesC();
	}

	public ArrayList<HashMap<String, String>> getListArticlesAcheter() {
		ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();

		// On déclare la HashMap qui contiendra les informations pour un item
		HashMap<String, String> map;
		if (db != null) {
			for (Article article : db.retrieveArticlesAchetes()) {
				map = new HashMap<String, String>();
				map.put("titre", StringUtils.troncateString(article.getTitre()));
				map.put("prixdebrief",
						IhmObjets.df.format(article.getPrixreduit()));
				listItem.add(map);
			}
		}
		return listItem;
	}

}
